/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.imenu.web.client.servlet;

import com.imenu.ejb.ImenuOrderFacade;
import com.imenu.ejb.ImenuStoreFacade;
import com.imenu.entity.ImenuOrder;
import com.imenu.entity.OrderStatus;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author yunzi
 */
@WebServlet(name = "ClientOrderServlet", urlPatterns = {"/clientOrder"})
public class ClientOrderServlet extends BaseServlet<ImenuOrder> {
    @EJB
    ImenuStoreFacade storeFacade;
    @EJB
    ImenuOrderFacade orderFacade;
    void orderList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<ImenuOrder> newList = orderFacade.findAll();
        List<ImenuOrder> acceptedList = new ArrayList<ImenuOrder>();
        List<ImenuOrder> doneList = new ArrayList<ImenuOrder>();
        Iterator<ImenuOrder> it = newList.iterator();
        while (it.hasNext()) {
            ImenuOrder order = it.next();

            if (OrderStatus.DONE.getValue().equals(order.getStatus())) {
                doneList.add(order);
                it.remove();
            } else if (OrderStatus.ACCEPTED.getValue().equals(order.getStatus())) {
                acceptedList.add(order);
                it.remove();
            }
        }
        //补充storeName属性，用于页面展示
        for(ImenuOrder order : newList){
            order.setStoreName(storeFacade.find(order.getStoreId()).getStoreName());
        }
        //request.setAttribute("doneList", doneList);
        request.setAttribute("newList", newList);
        request.setAttribute("newListSize", newList.size());
        //request.setAttribute("acceptedList", acceptedList);
        forward(request, response, "/order/orderList.jsp");
    }
    
}
